
const { Circle, Product, ProductTags, Series, Tag, VA } = require('../src/models');

const FileScanner = require('../src/services/fileScanner');
const DLsiteScraper = require('../src/services/dlsiteScraper');
const AddProduct = require('../src/services/productService')


const fileScanner = new FileScanner('D:/Programming/Projects/NodeJS/web-poster-wall/test/testDir');
const dlsiteScraper = new DLsiteScraper('http://127.0.0.1:7890');
const addProduct = new AddProduct();

// const router = express.Router();

// try {
async function main() {
    const results = await fileScanner.scan();
    for (const result of results) {
        console.log('\x1b[35m%s\x1b[0m', `开始扫描 ${result.path}，识别出 ${result.code}`);
        const productData = await dlsiteScraper.scrapeProduct(result.code);

        // console.log('productInfo是:', productInfo);

        if (productData) {
            // 调用函数插入数据
            const product = await addProduct.insertProductData(productData, result);
        }
    }
}

main();
// res.json({ message: 'Scan completed and database updated' });
// } catch (error) {
//     console.error('Error during scan:', error);
//     res.status(500).json({ error: 'An error occurred during the scan' });
// }